import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const power = ref()
    const user = ref({})
    const setToken = (newToken) => {
      token.value = newToken
    }
    const setPower = (newPower) => {
      power.value = newPower
    }
    const removeToken = () => {
      token.value = ''
    }
    const setUserInfo = (obj) => {
      user.value = obj
    }
    return {
      power,
      setPower,

      token,
      setToken,
      removeToken,

      user,
      setUserInfo
    }
  },
  {
    persist: {
      key: 'dmt-info',
      paths: ['token', 'user', 'power']
    }
  }
)
